define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'badge/index' + location.search,
                    add_url: 'badge/add',
                    edit_url: 'badge/edit',
                    del_url: 'badge/del',
                    multi_url: 'badge/multi',
                    import_url: 'badge/import',
                    table: 'badge',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'img', title: __('Img'), events: Table.api.events.image, formatter: Table.api.formatter.image,operate: false},
                        {field: 'img_no', title: __('Img_no'), events: Table.api.events.image, formatter: Table.api.formatter.image,operate: false},
                        // {field: 'rule_num', title: __('Rule_num')},
                        // {field: 'desc', title: __('Desc'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: function(value,row,index) {
                                var that = $.extend({}, this);
                                    // $(table).data("operate-edit", true); //编辑operate-edit  - 删除按钮operate-del
                                $(table).data("operate-del", null); // 列表页面编辑按钮隐藏
                                that.table = table;
                                return Table.api.formatter.operate.call(that, value, row, index);

                            }}
                        //Table.api.formatter.operate
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
